// SPDX-License-Identifier: GPL-2.0
/*
 * ZONE
 *
 * (C) 2024.05.01 BuddyZhang1 <buddy.zhang@aliyun.com>
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>

static int __init BiscuitOS_init(void)
{
	struct page *page;

	/** ALLOC PAGE FROM ZONE_DMA **/

	page = alloc_page(GFP_DMA);
	if (!page) {
		printk("ERROR: ALLOC ON ZONE_DMA\n");
		return -ENOMEM;
	}
	printk("PAGE: %#lx FROM %s\n", page_to_pfn(page),
				       page_zone(page)->name);
	__free_page(page);

	/** ALLOC PAGE FROM ZONE_DMA32 **/

	page = alloc_page(GFP_DMA32);
	if (!page) {
		printk("ERROR: ALLOC ON ZONE_DMA32\n");
		return -ENOMEM;
	}
	printk("PAGE: %#lx FROM %s\n", page_to_pfn(page),
				       page_zone(page)->name);
	__free_page(page);

	/** ALLOC PAGE FROM ZONE_NORMAL **/

	page = alloc_page(GFP_KERNEL);
	if (!page) {
		printk("ERROR: ALLOC ON ZONE_DMA\n");
		return -ENOMEM;
	}
	printk("PAGE: %#lx FROM %s\n", page_to_pfn(page),
				       page_zone(page)->name);
	__free_page(page);

	return 0;
}

static void __exit BiscuitOS_exit(void) { }

module_init(BiscuitOS_init);
module_exit(BiscuitOS_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("BiscuitOS <buddy.zhang@aliyun.com>");
MODULE_DESCRIPTION("Linux Dream Motion on BiscuitOS");
